﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using SmallERP.COM;

namespace SmallERP.Host
{
    public static class DateTransfer
    {
        public static string LocalIPadress { get; set; }

        public static bool IsPrintLine { get; set; }
        public static bool IsAutoCut { get; set; }
        public static int SelectBarCodeType { get; set; }
        public static double MinPhotoRemarkLength { get; set; }

        public static string PhotoRemarkOrder { get; set; }
        public static int CutMinPhotoNum { get; set; }
        public static int PhotoRemarkFlag { get; set; }//照片区分标志0双色块，1为底色
        public static int TextAlignType { get; set; }
        public static int SaveFileType { get; set; }
        //public List<int> WaitClearFolderBoardID = new List<int>();
        public static int BoardLineWidth { get; set; }
        public static Color BackColor
        {
            get
            {

                if (string.IsNullOrEmpty(ColorBackStr))
                {
                    return Color.Gray;

                }
                else
                {
                    string[] colorArray = ColorBackStr.Split(',');
                    return Color.FromArgb(Convert.ToInt32(colorArray[0]), Convert.ToInt32(colorArray[1]), Convert.ToInt32(colorArray[2]));
                }
            }
        }
        public static string ColorBackStr { get; set; }
        //public static Color Bac{get;set;
        public static int AddIccByType { get; set; }
        public static string TextFont { get; set; }
        public static int TextFontSize { get; set; }

        public static int HistoryDataSaveDays { get; set; }
        public static int BarCodeSize { get; set; }
        public static int PhotosizeUnit { get; set; }
        public static string LineBackStr { get; set; }
        public static Color LineBack
        {
            get
            {

                if (string.IsNullOrEmpty(LineBackStr))
                {
                    return Color.Gray;

                }
                else
                {
                    string[] colorArray = LineBackStr.Split(',');
                    return Color.FromArgb(Convert.ToInt32(colorArray[0]), Convert.ToInt32(colorArray[1]), Convert.ToInt32(colorArray[2]));
                }
            }
        }
        public static bool IsPrintBarCodeInPicture { get; set; }
        public static string RemarkKeysColor { get; set; }
        public static string CutInfoPosition { get; set; }
        public static int RemarkInPicBottomOrTop { get; set; }
        public static int RemarkInPicRightOrLeft { get; set; }
        public static bool TwoCutFlag { get; set; }

        public static int MerginMM
        {
            get
            {
                string str = IniFile.IniReadValue("Host", "MerginMM");
                if (string.IsNullOrEmpty(str))
                {
                    return 0;
                }
                else
                {
                    return Convert.ToInt32(str);
                }
            }
            set
            {
                IniFile.IniWriteValue("Host", "MerginMM", value.ToString());
            }
        }

        public static bool CutNobarCode
        {
            get
            {
                string str = IniFile.IniReadValue("Host", "CutNobarCode");
                if (string.IsNullOrEmpty(str))
                {
                    return false;
                }
                else
                {
                    return Convert.ToBoolean(str);
                }
            }
            set
            {
                IniFile.IniWriteValue("Host", "CutNobarCode", value.ToString());
            }
        }

        public static Bleed CurrentBleed
        {
            get
            {
                string str = IniFile.IniReadValue("Host", "Bleed");
                if (string.IsNullOrEmpty(str))
                {
                    str = "0,0";
                }
                string[] bleedStrArr = str.Split(',');
                int ty = 0;
                double va = 0;
                if (bleedStrArr.Count() >= 2)
                {
                   
                    try
                    {                
                    ty= Convert.ToInt32(bleedStrArr[0]);
                    va = Convert.ToDouble(bleedStrArr[1]);
                    }
                    catch (Exception exception)
                    {                     
                    }
                }
                return new Bleed(ty,va);

            }
            set
            {
                if (value != null)
                {
                    string strVal = value.Type + "," + value.Value;
                    IniFile.IniWriteValue("Host", "Bleed", strVal);
                }
                else
                {
                    IniFile.IniWriteValue("Host", "Bleed", "0,0");
                }
            }
        }
    }

    public class Bleed
    {
        public Bleed(int t, double v)
        {
            Type = t;
            Value = v;
        }

        public int Type { get; set; }

        public string DisplayType
        {
            get
            {
                if (Type == 0)
                {
                    return "固定值";
                }
                else if (Type == 1)
                {
                    return "百分比";
                }
                else
                {
                    return "";
                }
            }
        }

        public double Value { get; set; }
    }
}

